
package Communication;

import java.net.*;
import java.io.*;

public class EnclosureClient {

    int portNumber;
    Socket s;
    ObjectInputStream ois;
    ObjectOutputStream oos;

    public EnclosureClient(int portNumber) throws IOException {
        System.out.println("Starting!!...");
        this.portNumber = portNumber;
    }


    public void connectToServer() throws IOException {
        System.out.println("Make Socket!!...");
        s = new Socket("localhost", portNumber);

        System.out.println("Socket Connection Established...");
    }


    public Boolean sendUpdate() throws IOException {
        System.out.println("Trying to send data from client...");
        oos = new ObjectOutputStream(s.getOutputStream());
        oos.writeObject("this UPDATE SENT from CLIENT");
        return true;
    }


    public void receiveUpdate() throws IOException, ClassNotFoundException {
        try {
            System.out.println("Client is Looking for Received Data!!!");

            ois = new ObjectInputStream(s.getInputStream());
            String message = (String) ois.readObject();
            System.out.println("Message Received: " + message);
        } catch (Exception yui) {
            System.out.println(yui);
        }
    }
}
